﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.Options;

namespace Batman.Cms.Core.Razor
{
    public class PluginRazorViewEngineOptionsSetup : ConfigureOptions<RazorViewEngineOptions>
    {
        public PluginRazorViewEngineOptionsSetup(IHostingEnvironment hostingEnvironment) :
            base(options => ConfigureRazor(options, hostingEnvironment))
        {

        }
        private static void ConfigureRazor(RazorViewEngineOptions options, IHostingEnvironment env)
        {
            //if (env.IsDevelopment())
            //{
                options.FileProviders.Add(new DeveloperViewFileProvider(env));
            //}

            //if (env.IsDevelopment())
            //{
                options.ViewLocationFormats.Add($"/Porject.RootPath/Batman.Cms.Core" + "/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
                options.ViewLocationFormats.Add($"/Porject.RootPath/Batman.Cms.Core" + "/Views/Shared/{0}" + RazorViewEngine.ViewExtension);
                options.ViewLocationFormats.Add($"/Porject.RootPath/Batman.Cms.Core" + "/Views/{0}" + RazorViewEngine.ViewExtension);
            //}
            //else
            //{
            //    // TODO:规划生产环境的公共模板
            //    options.ViewLocationFormats.Add($"/Common" + "/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
            //    options.ViewLocationFormats.Add($"/Common" + "/Views/Shared/{0}" + RazorViewEngine.ViewExtension);
            //    options.ViewLocationFormats.Add($"/Common" + "/Views/{0}" + RazorViewEngine.ViewExtension);
            //}
            options.ViewLocationFormats.Add("/Views/{0}" + RazorViewEngine.ViewExtension);
        }
    }
}
